package com.central.modules.job.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.central.common.page.PageData;
import com.central.common.utils.ConvertUtils;
import com.central.common.utils.Result;
import com.central.modules.job.dto.ScheduleJobLogDTO;
import com.central.modules.job.entity.ScheduleJobLogEntity;
import com.central.modules.job.model.ScheduleJobLogQueryBean;
import com.central.modules.job.service.ScheduleJobLogService;
import lombok.AllArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 定时任务日志
 *
 */
@RestController
@RequestMapping("/sys/scheduleLog")
@AllArgsConstructor
public class ScheduleJobLogController {
    private final ScheduleJobLogService scheduleJobLogService;

    @GetMapping("page")
    @RequiresPermissions("sys:schedule:log")
    public Result<PageData<ScheduleJobLogDTO>> pageSearch(ScheduleJobLogQueryBean queryBean) {
        IPage<ScheduleJobLogEntity> iPage = scheduleJobLogService.pageSearch(queryBean);
        return Result.succeed(PageData.copy(iPage, ConvertUtils.sourceToTarget(iPage.getRecords(),ScheduleJobLogDTO.class)));
    }

    @GetMapping("{id}")
    @RequiresPermissions("sys:schedule:log")
    public Result<ScheduleJobLogDTO> info(@PathVariable("id") Long id) {
        ScheduleJobLogEntity log = scheduleJobLogService.get(id);
        return Result.succeed(ConvertUtils.sourceToTarget(log,ScheduleJobLogDTO.class));
    }
}